<template>
  <div class="app-container">
    <el-card class="box-card">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="会议室名称" prop="meettingId" label-width="90px">
        <el-input
          v-model="queryParams.meettingId"
          placeholder="请输入会议室名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="roomList"
      border
      :show-header="false"
      :row-style="{height: '10'}"
      :cell-style="{padding: '23px'}">
      <el-table-column align="center" prop="meettingRoom.name" style="height: 200px">
        <template slot-scope="scope">
          <image-preview :src="scope.row.image" :width="180" :height="110" style="float: left"/>
          <div class="content">
            <span class="title">{{ scope.row.name }}</span>
            <div class="fontLine">
              <span class="count">坐席{{ scope.row.count }}</span>
              <span class="position">{{ scope.row.position }}</span>
            </div>
<!--            <div class="tagLine">
              <el-tag class="tag" type="info" size="mini" color="white" effect="light" v-for="tag in scope.row.device">{{ tag }}</el-tag>
            </div>-->
          </div>

        </template>
      </el-table-column>
      <el-table-column align="center" prop="">
        <template slot-scope="scope">
          <span style="font-size: 17px;font-weight: bold;margin-left:-95px">请选择会议日期和时间</span>
            <el-date-picker
              style="display: block;margin-left: 90px;margin-top:10px;width: 200px"
              v-model="scope.row.datee"
              align="right"
              type="date"
              placeholder="选择日期"
              :picker-options="pickerOptions"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd">
            </el-date-picker>
          <el-time-select
            style="width: 140px;margin:15px 10px 0 20px;"
            placeholder="起始时间"
            v-model="scope.row.startDate"
            :picker-options="{
            start: '10:20',
            step: '00:20',
            end: '18:30',
          }">
          </el-time-select>
          -
          <el-time-select
            style="width: 140px;margin:15px 0 0 10px;"
            placeholder="结束时间"
            v-model="scope.row.endDate"
            :picker-options="{
            start: '10:20',
            step: '00:20',
            end: '18:30',
            // minTime: startTime
          }">
          </el-time-select>
          <el-link :underline="false" style="position: relative;left: 20px;bottom: 35px" @click="setAppoint(scope.row)">
            去设置预约信息<i class="el-icon-right"></i>
          </el-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    </el-card>
  </div>
</template>
<style>
.content{
  margin: 15px 0 0 25px;
  float: left;
  width: 200px;
  height: 90px;
}
.title{
  font-weight: bold;
  font-size: 20px;
  display: block;
  float: left;
  margin-bottom: 0;
}
.fontLine{
  float: left;
  margin-right: 40px;
}
.count{
  float: left;
  margin: 10px 20px 0 0;
}
.position{
  float: left;
  margin-top: 10px;
}
.tagLine{
  float: left;
  margin-top: 15px;
  margin-left: -8px;
  width: 280px;
  height: 30px;
}
.tag{
  float: left;
  color: black;
  margin-left: 5px;
}
</style>
<script>
import { listRoom, getRoom, delRoom, addRoom, updateRoom } from "@/api/system/room";

export default {
  name: "Room",
  dicts: ['sys_meetting_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会议室信息表表格数据
      roomList: [],
      duration:'',
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      value: new Date(),
      startTime:new Date().getHours().toString().padStart(2, '0')+":"+new Date().getMinutes().toString().padStart(2, '0'),
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        status: null,
      },
      // 表单参数
      form: {},
      //设备备选值
      deviceOptions:['投影仪','白板','电脑','空调','沙发'],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() <= Date.now();
        },
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '明天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }]
      },
      value2: '',
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询会议室信息表列表 */
    getList() {
      this.loading = true;
      listRoom(this.queryParams).then(response => {
        this.roomList = response.rows;
        this.total = response.total;
        this.roomList.forEach(function(n,i){
          n.device = JSON.parse(JSON.stringify(n.device)).split(',');
        })
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        image: null,
        name: null,
        count: null,
        position: null,
        device: [''],
        status: null,
        common: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /* 设置预约信息 */
    setAppoint(row){
      const startdateStr = row.datee+" "+row.startDate;
      const enddateStr = row.datee+" "+row.endDate;
      if(row.datee&&row.startDate&&row.endDate){
        //判断开始时间是否小于结束时间
        if(startdateStr<enddateStr){
          // 分割时间字符串并创建Date对象
          var time1Parts = row.startDate.split(":");
          var time2Parts = row.endDate.split(":");
          var date1 = new Date(0, 0, 0, time1Parts[0], time1Parts[1]);
          var date2 = new Date(0, 0, 0, time2Parts[0], time2Parts[1]);
          // 计算时间差（以毫秒为单位）
          var timeDiff = date2 - date1;
          // 将时间差转换为分钟
          this.duration = timeDiff / (1000 * 60)+'';
          //添加路由
          this.$router.push({
            name:'SetAppoint',
            params:{
              datee:row.datee,
              startDate:row.startDate,
              endDate:row.endDate,
              id:row.id,
              duration:this.duration
            }
          })
        }else{
          this.$message({
            message: '会议开始时间不能大于或等于结束时间',
            type: 'warning'
          });
        }

      }else{
        this.$message({
          message: '请设置预约日期和时间',
          type: 'warning'
        });
      }

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>
